/**
 ******************************************************************************
 * @file    wdog.c
 * @author  hyseim software Team
 * @date    27-Mar-2024
 * @brief   This file provides all the tmp functions.
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2020 Hyseim. Co., Ltd.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */

/* Includes ------------------------------------------------------------------*/
#include "wdog.h"

/** @addtogroup IM110GW_Driver
 * @{
 */

/** @defgroup WDOG
 * @brief WDOG driver modules
 * @{
 */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup WDOG_Private_Functions
  * @{
  */

/**
 * @brief  Enable WDOG counter and interrupt.
 * @return None
 */
void WDOG_Enable(void)
{
    WDOG->WDOGCONTROL |= (WDOG_CONTROL_INT_EN);
}

/**
 * @brief  Disabke WDOG counter and interrupt.
 * @return None
 */
void WDOG_Disable(void)
{
    WDOG->WDOGCONTROL &= ~(WDOG_CONTROL_INT_EN);
}

/**
 * @brief  Sets WDOG reset MCU function.
 * @return None
 */
void WDOG_SetResetMode(void)
{
    WDOG->WDOGCONTROL |= (WDOG_CONTROL_RESET_EN);
}

/**
 * @brief  Set Window mode.
 * @return None
 */
void WDOG_SetWindowMode(void)
{
    WDOG->WDOGCONTROL |= (WDOG_CONTROL_WINDOW_MODE);
}

/**
 * @brief  Set debug mode.
 * @return None
 */
void WDOG_SetDebugMode(void)
{
    WDOG->WDOGCONTROL |= (WDOG_CONTROL_DEBUG_MODE);
}

/**
 * @brief  Disables write accesses to all other registers of WDOG.
 * @return None
 */
void WDOG_Lock(void)
{
    WDOG->WDOGLOCK |= (WDOG_LOCK_ENABLE);
}

/**
 * @brief  Allow write operations on WDOG within 128 pclk cycles.
 * @return None
 */
void WDOG_Unlock(void)
{
    WDOG->WDOGLOCK = WDOG_UNLOCK_KEY;
}

/**
 * @brief  Sets the value of the WDOG window.
 * @return None
 */
void WDOG_SetWindowValue(uint32_t WindowValue)
{
    WDOG->WDOGWINVAL = WindowValue;
}

/**
 * @brief  Sets the WDOG counter value.
 * @return None
 */
void WDOG_SetLoadValue(uint32_t LoadValue)
{
    WDOG->WDOGLOAD = LoadValue;
}

/**
 * @brief  Gets the current count value of WDOG.
 * @return WDOG current counter value
 */
uint32_t WDOG_GetCounterValue(void)
{
    return WDOG->WDOGVALUE;
}

/**
 * @brief  Checks whether the specified WDOG interrupt has occurred or not.
 * @return The new state of the WDOG_STATUS (SET or RESET)
 */
FlagStatus_t WDOG_GetITStatus(void)
{
    ITStatus_t bitstatus = RESET;

    if ((WDOG->WDOGMIS & WDOG_MIS_INT_STATUS_MASK) == SET)
    {
        bitstatus = SET;
    }
    else
    {
        bitstatus = RESET;
    }
    return bitstatus;
}

/**
 * @brief  Clears the WDOG's pending flags.
 * @return None
 */
void WDOG_ClearITFlag(void)
{
    WDOG->WDOGINTCLR = (uint32_t)SET;
}


/**
 * @brief  Config test mode.
 * @param  TestMode_En: places the watchdog into integration test mode.
 * @return None
 */
void WDOG_ConfigTestMode(uint8_t TestMode_En)
{
    WDOG->WDOGITCR = TestMode_En;
}

/**
 * @brief  Set WDOG test mode interrupt and reset status.
 * @param  TestINTValue: Value output on WDOGINT when in integration test mode.
 * @param  TestResetValue: Value output on WDOGRES when in integration test mode.
 * @return None
 */
void WDOG_SetTestMode_Status(uint8_t TestINTValue, uint8_t TestResetValue)
{
    WDOG->WDOGITOP = TestINTValue | TestResetValue;
}

/**
  * @}
  */

/**
 * @}
 */

/**
 * @}
 */
